let arr = [2, 5, 7, 9, 15]
function binarySearch(array, target) {
  let start = 0,
    end = array.length - 1,
    middle, element
  while (start <= end) {
    middle = Math.floor((start + end) / 2)
    element = array[middle]
    if (element === target) {
      return middle
    } else if (element < target) {
      start = middle + 1
    } else {
      end = middle - 1
    }
  }
  return -1
}

binarySearch(arr, 7)